<template>
	<view class="apps">
		<view class="ptb20 plr20">
		<uv-form labelPosition="top" labelWidth="auto" :model="userInfo" :rules="rules" ref="form">
			<uv-form-item label="年龄" prop="age" borderBottom>
				<uv-input type="number" v-model="userInfo.age" border="none">
				</uv-input>
			</uv-form-item>
			<uv-form-item label="性别" prop="sex_str" borderBottom @click="showSexSelect">
				<uv-input v-model="userInfo.sex_str" disabled disabledColor="#ffffff" placeholder="请选择性别" border="none">
				</uv-input>
				<template v-slot:right>
					<uv-icon name="arrow-right"></uv-icon>
				</template>
			</uv-form-item>
			<uv-form-item label="身高" prop="height" borderBottom>
				<uv-input type="number" v-model="userInfo.height" border="none">
				</uv-input>
				<template v-slot:right>
					<text class="f14">厘米</text>
				</template>
			</uv-form-item>
			<uv-form-item label="体重" prop="weight" borderBottom>
				<uv-input type="number" v-model="userInfo.weight" border="none">
				</uv-input>
				<template v-slot:right>
					<text class="f14">千克</text>
				</template>
			</uv-form-item>
			<uv-form-item label="主要健康问题/诊断" prop="health" >
				<uv-textarea v-model="userInfo.health" placeholder="请输入内容"></uv-textarea>
			</uv-form-item>
			<uv-form-item label="过敏史" prop="qustion" >
				<uv-textarea v-model="userInfo.qustion" placeholder="请输入内容"></uv-textarea>
			</uv-form-item>
			<uv-form-item label="传染病" prop="infection" >
				<uv-textarea v-model="userInfo.infection" placeholder="请输入内容"></uv-textarea>
			</uv-form-item>
			<uv-form-item label="特殊生理状态" prop="physiology" >
				<uv-textarea v-model="userInfo.physiology" placeholder="请输入内容"></uv-textarea>
			</uv-form-item>
			<uv-form-item label="既往刮痧/拔罐/相关疗法反应" prop="remark" >
				<uv-textarea v-model="userInfo.remark" placeholder="请输入内容"></uv-textarea>
			</uv-form-item>
			<uv-button type="primary" text="提交" customStyle="margin-top: 10px" @click="submit"></uv-button>
			<uv-button type="warning" text="重置" customStyle="margin-top: 10px" @click="reset"></uv-button>
		</uv-form>
		<uv-action-sheet ref="sexSelect" :actions="actions" title="请选择性别" description="如果选择保密会报错" @select="sexSelect">
		</uv-action-sheet>
		</view>
	</view>
</template>

<script>
	let app;
	export default {
		data() {
			return {
				userInfo: {
					age: '',
					sex: '',
					sex_str:'',
					height:'',
					weight:'',
					health:'',
					qustion:'',
					abnormal:'',
					infection:'',
					physiology:'',
				},
				actions: [{
					name: '男',
					id:"opt0"
				}, {
					name: '女',
					id:"opt1"
				} ],
				rules: {
					'age': {
						type: 'string',
						required: true,
						message: '请填写年龄',
						trigger: ['blur', 'change']
					},
					'sex_str': {
						type: 'string',
						required: true,
						message: '请选择性别',
						trigger: ['blur', 'change']
					},
					'height':{
						type: 'string',
						required: true,
						message: '请填写身高',
						trigger: ['blur', 'change']
					},
					'weight':{
						type: 'string',
						required: true,
						message: '请填写体重',
						trigger: ['blur', 'change']
					},
				},
			}
		},
		onLoad(){
			app = this;
			app.getHealth();
		},
		methods: {
			sexSelect(e){
				console.log(e);
				app.userInfo.sex_str = e.name;
				app.userInfo.sex = e.id;
			},
			// 提交
			submit() {
				// 如果有错误，会在catch中返回报错信息数组，校验通过则在then中返回true
				this.$refs.form.validate().then(res => {
					app.util.request({
						url:"/mpwechat/healthadd",
						data: app.userInfo,
						success:function(rlt){
							if(rlt.code == 1){
								app.alert('提交成功');
								uni.navigateBack();
							}
							
						}
					})
				}).catch(errors => {

				})
			},
			// 重置
			reset() {
				this.$refs.form.resetFields();
				this.$refs.form.clearValidate();
			},
			// 性别选择
			showSexSelect() {
				this.$refs.sexSelect.open();
			},
			getHealth(){
				app.request({
					url:"/mpwechat/health",
					type:"post",
					success:function(rlt){
						if(rlt.code == 1){
							app.userInfo = rlt.data;
						}
					}
				})
			}
		}
	}
</script>

<style>

</style>
